package CH01数组结构.LeetCode栈与队列;

import java.util.Stack;

public class LC232 {
    class MyQueue {
        Stack<Integer> stackA;
        Stack<Integer> stackB;

        public MyQueue() {
            stackA = new Stack<>();
            stackB = new Stack<>();
        }

        public void push(int x) {
            stackA.push(x);
        }

        public int pop() {
            while (stackA.size() != 1) {
                stackB.push(stackA.pop());
            }
            int ret = stackA.pop();
            while (!stackB.isEmpty()) {
                stackA.push(stackB.pop());
            }
            return ret;
        }

        public int peek() {
            while (!stackA.isEmpty()) {
                stackB.push(stackA.pop());
            }
            int ret = stackB.peek();
            while (!stackB.isEmpty()) {
                stackA.push(stackB.pop());
            }
            return ret;
        }

        public boolean empty() {
            return stackA.isEmpty();
        }
    }
}